package com.duowan.realtime.thrift;

import org.apache.thrift.TProcessor;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TBinaryProtocol.Factory;
import org.apache.thrift.server.AbstractNonblockingServer.AbstractNonblockingServerArgs;
import org.apache.thrift.server.TNonblockingServer;
import org.apache.thrift.server.TServer;
import org.apache.thrift.server.TThreadPoolServer;
import org.apache.thrift.server.TThreadPoolServer.Args;
import org.apache.thrift.transport.TNonblockingServerSocket;
import org.apache.thrift.transport.TNonblockingServerTransport;
import org.apache.thrift.transport.TServerSocket;
import org.apache.thrift.transport.TTransportException;

import com.duowan.realtime.thirft.api.BloomFilterService;
import com.duowan.realtime.thrift.Hello.Iface;

public class HelloServiceServer {

	public static void main(String[] args) throws TTransportException {
		// 设置服务端口
		TServerSocket serverTransport = new TServerSocket(8888);
		//TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(8888);
		// 设置协议工厂
		
		Factory proFactory = new TBinaryProtocol.Factory();
		TProcessor processor = new Hello.Processor<Iface>(new HelloServiceImpl());
		Args params = new Args(serverTransport);
		//TNonblockingServer.Args params = new  TNonblockingServer.Args(serverTransport);
		params.inputProtocolFactory(proFactory);
		params.processor(processor);
		TServer server = new TThreadPoolServer(params);
		//TServer server = new TNonblockingServer(params);
		System.out.println("Start server on port 8888...");
		server.serve();
		
//		TServerSocket serverTransport = new TServerSocket(port);
//		// 设置协议工厂
//		Factory proFactory = new TBinaryProtocol.Factory();
//		TProcessor processor = new BloomFilterService.Processor<Iface>(new BloomFilterServiceImpl());
//		Args params = new Args(serverTransport);
//		params.inputProtocolFactory(proFactory);
//		params.processor(processor);
//		TServer server = new TThreadPoolServer(params);
//		LOG.info("Start server on port:" + port);
//		server.serve();
	}
}
